home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Missile Battery.lua < prev    next >
Text File  |  2010-08-31  |  6KB  |  153 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Missile Battery + Projectile Missile
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.missilebat={}
  10. cc.missilebat.missile={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.missilebat.gfx_wpn=loadgfx("weapons/missilebattery.bmp")                -- Weapon Image
  14. setmidhandle(cc.missilebat.gfx_wpn)
  15. cc.missilebat.gfx_pro=loadgfx("weapons/missile.bmp")                    -- Projectile Image
  16. setmidhandle(cc.missilebat.gfx_pro)
  17. cc.missilebat.sfx_attack=loadsfx("rocketrelease.wav")                    -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Missile Battery
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.missilebat.id=addweapon("cc.missilebat","Missile Battery",cc.missilebat.gfx_wpn,0,3)    -- Add Weapon (0 uses, first in round 3)
  24. cc.missilebat.ammo=9                                                    -- 9 Missiles
  25.  
  26. function cc.missilebat.draw()                                            -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(160,200,160)
  30.     drawinhand(cc.missilebat.gfx_wpn,6,0)
  31.     -- HUD ammobar
  32.     if cc.missilebat.ammo-weapon_shots>0 then
  33.         hudammobar(cc.missilebat.ammo-weapon_shots,cc.missilebat.ammo)
  34.     end
  35.     -- HUD Crosshair
  36.     if cc.missilebat.ammo-weapon_shots>0 then
  37.         hudcrosshair(7,3)
  38.     end
  39. end
  40.  
  41. function cc.missilebat.attack(attack)                                    -- Attack
  42.     -- Decrement timer
  43.     if weapon_timer>0 then
  44.         weapon_timer=weapon_timer-1
  45.     end
  46.     if (weapon_shots<cc.missilebat.ammo) and (attack==1) and (weapon_timer<=0) then
  47.         -- No more weapon switching!
  48.         useweapon(0)
  49.         playsound(cc.missilebat.sfx_attack)
  50.         weapon_shots=weapon_shots+1
  51.         weapon_timer=15
  52.         id=createprojectile(cc.missilebat.missile.id)
  53.         projectiles[id]={}
  54.         -- Ignore collision with current player at beginning
  55.         projectiles[id].ignore=playercurrent()
  56.         -- Set initial position of projectile
  57.         projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  58.         projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  59.         -- Initial movement
  60.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
  61.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
  62.         projectiles[id].x=projectiles[id].x-projectiles[id].sx
  63.         projectiles[id].y=projectiles[id].y-projectiles[id].sy
  64.         cc.missilebat.missile.move(id,0)
  65.         -- Set speed of projectile
  66.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*10.0
  67.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*10.0
  68.         -- Effects
  69.         recoil(5)
  70.         -- End Turn
  71.         if weapon_shots>=cc.missilebat.ammo then
  72.             endturn()
  73.         end
  74.     end
  75. end
  76.  
  77. --------------------------------------------------------------------------------
  78. -- Projectile: missile
  79. --------------------------------------------------------------------------------
  80.  
  81. cc.missilebat.missile.id=addprojectile("cc.missilebat.missile")        -- Add Projectile
  82.  
  83. function cc.missilebat.missile.draw(id)                                -- Draw
  84.     -- Setup draw mode
  85.     setblend(blend_alpha)
  86.     setalpha(1)
  87.     setcolor(255,255,255)
  88.     setscale(1,1)
  89.     -- Calculate projectile rotation
  90.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  91.     -- Draw projectile
  92.     drawimage(cc.missilebat.gfx_pro,projectiles[id].x,projectiles[id].y)
  93.     -- Draw Arrow if out of Screen
  94.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  95. end
  96.  
  97. function cc.missilebat.missile.update(id)                            -- Update
  98.     -- Move
  99.     cc.missilebat.missile.move(id,1)
  100. end
  101.  
  102. function cc.missilebat.missile.move(id,fx)
  103.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  104.     -- Particle Tail
  105.     if (fx==1) then
  106.         particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  107.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  108.         particlefadealpha(0.01)
  109.         particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
  110.         particlefadealpha(0.04)
  111.     end
  112.     -- Wind + Gravity influence on speed
  113.     projectiles[id].sx=projectiles[id].sx+getwind()*0.5
  114.     projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
  115.     -- Move (in substep loop for optimal collision precision)
  116.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  117.     msubx=projectiles[id].sx/msubt
  118.     msuby=projectiles[id].sy/msubt
  119.     for i=1,msubt,1 do
  120.         projectiles[id].x=projectiles[id].x+msubx
  121.         projectiles[id].y=projectiles[id].y+msuby
  122.         -- Collision
  123.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  124.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  125.                 -- Cause damage
  126.                 arealdamage(projectiles[id].x,projectiles[id].y,70,20)
  127.                 -- Destroy terrain
  128.                 terrainexplosion(projectiles[id].x,projectiles[id].y,20,1)
  129.                 -- Crater
  130.                 grey=math.random(0,40)
  131.                 if math.random(0,1)==1 then
  132.                     terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  133.                 else
  134.                     terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  135.                 end
  136.                 -- Free projectile
  137.                 freeprojectile(id)
  138.                 break
  139.             end
  140.         else
  141.             projectiles[id].ignore=0
  142.         end
  143.         -- Water
  144.         if (projectiles[id].y)>getwatery()+5 then
  145.             -- Effects
  146.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  147.             playsound(sfx_hitwater1)
  148.             -- Free projectile
  149.             freeprojectile(id)
  150.             break
  151.         end
  152.     end
  153. end